package com.xuexiang.xuidemo.slice;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.util.AppCfig;
import com.xuexiang.xuidemo.util.ToastUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * 各种Toast弹出框
 */
public class XulPopupWindowToastSlice extends AbilitySlice implements Component.ClickedListener {
    private Context mContext;
    private Image image_back;
    private DirectionalLayout dl_one,dl_two,dl_three,dl_four,dl_five;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_xulpopupwindow_toast);
        initComponent();
        initClickedListener();
    }
    public void  initComponent(){
        mContext=XulPopupWindowToastSlice.this;
        image_back=(Image) findComponentById(ResourceTable.Id_image_back);
        dl_one=(DirectionalLayout) findComponentById(ResourceTable.Id_dl_one);
        dl_two=(DirectionalLayout) findComponentById(ResourceTable.Id_dl_two);
        dl_three=(DirectionalLayout) findComponentById(ResourceTable.Id_dl_three);
        dl_four=(DirectionalLayout) findComponentById(ResourceTable.Id_dl_four);
        dl_five=(DirectionalLayout) findComponentById(ResourceTable.Id_dl_five);

    }
    private void initClickedListener() {
        image_back.setClickedListener(this);
        dl_one.setClickedListener(this);
        dl_two.setClickedListener(this);
        dl_three.setClickedListener(this);
        dl_four.setClickedListener(this);
        dl_five.setClickedListener(this);
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_dl_one:
                ToastUtil.showToast(getContext(),"This is an error toast.",new Color(AppCfig.one_black), ResourceTable.Media_ic_action_close,0);
                break;
            case ResourceTable.Id_dl_two:
                ToastUtil.showToast(getContext()," Success!",new Color(AppCfig.two_black), ResourceTable.Media_ic_action_tick,0);
                break;
            case ResourceTable.Id_dl_three:
                ToastUtil.showToast(getContext()," Here is some info you.",new Color(AppCfig.three_black), ResourceTable.Media_ic_fab_error,0);
                break;
            case ResourceTable.Id_dl_four:
                ToastUtil.showToast(getContext()," Beware of the dog.",new Color(AppCfig.four_black), ResourceTable.Media_ic_fab_error,0);
                break;
            case ResourceTable.Id_dl_five:
                ToastUtil.showToastCENTER(getContext(),"Normal toast w/o icon");
                break;
            default:
                ToastUtil.showToast(getContext(),"提交成功");
                break;
        }
    }
    public void inTents(String AbilityName) {
        Intent intent =new Intent();
        Operation operation=new Intent.OperationBuilder().withDeviceId("")
                .withBundleName("com.xuexiang.xuidemo")
                .withAbilityName("com.xuexiang.xuidemo."+AbilityName).build();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
